//
//  MessageListCell.m
//  JPWords
//
//  Created by 梁淑婷 on 2024/6/19.
//

#import "MessageListCell.h"

@interface MessageListCell()

@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UILabel *contentLabel;
@property(nonatomic,strong)UILabel *timeLabel;
@property(nonatomic,strong)UIView *point;

@end

@implementation MessageListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self createUI];
    }
    return self;
}

-(void)createUI{
    
    self.contentView.backgroundColor = UIColorHex(0xF2F7F6);
    
    UIView *logoView = [[UIView alloc]init];
    logoView.backgroundColor = KThemeColor;
    logoView.layer.cornerRadius = 24;
    logoView.layer.masksToBounds = YES;
    [self.contentView addSubview:logoView];
    [logoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(@48);
        make.left.mas_equalTo(@16);
        make.top.mas_equalTo(@18);
    }];
    
    UIImageView *coinImageView = [[UIImageView alloc]init];
    coinImageView.backgroundColor = [UIColor clearColor];
    coinImageView.image = [UIImage imageNamed:@"message_alarm"];
    [logoView addSubview:coinImageView];
    [coinImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(@24);
        make.centerX.centerY.mas_equalTo(logoView);
    }];
    
    __weak typeof(self)self_weak_ = self;

    self.point = [[UIView alloc]init];
    self.point.backgroundColor = UIColorHex(0xFE4A4B);
    self.point.layer.cornerRadius = 5;
    self.point.layer.masksToBounds = YES;
    [self.contentView addSubview:self.point];
    [self.point mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(@10);
        make.right.mas_equalTo(logoView.mas_right).offset(-2);
        make.top.mas_equalTo(logoView.mas_top).offset(2);
    }];
    self.point.hidden = YES;
    
    self.titleLabel = [[UILabel alloc]init];
    self.titleLabel.font = JPUIFontPingFangSCMedium(16);
    self.titleLabel.textColor = KFontBlackColor;
    self.titleLabel.text = @"系统消息";
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(logoView.mas_right).offset(10);
        make.right.mas_equalTo(@-16);
        make.height.mas_equalTo(@22);
        make.top.mas_equalTo(@18);
    }];
    
    self.contentLabel = [[UILabel alloc]init];
    self.contentLabel.font = JPUIFontPingFangSCRegular(14);
    self.contentLabel.textColor = KFontGrayColor;
    self.contentLabel.numberOfLines = 0;
    [self.contentView addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(logoView.mas_right).offset(10);
        make.top.mas_equalTo(self_weak_.titleLabel.mas_bottom).offset(5);
        make.right.mas_equalTo(@-16);
    }];
    
    self.timeLabel = [[UILabel alloc]init];
    self.timeLabel.font = JPUIFontInterRegular(13);
    self.timeLabel.textColor = KFontGrayColor;
    [self.contentView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self_weak_.contentLabel.mas_left);
        make.bottom.mas_equalTo(@-18);
        make.height.mas_equalTo(@16);
    }];
    
}

-(void)setModel:(NewsListModel *)model{
    _model = model;
    
    self.contentLabel.text = model.content;
    self.timeLabel.text = model.createTime;
    if(model.isRead.integerValue == 1){
        self.point.hidden = YES;
    }else{
        self.point.hidden = NO;
    }
}

@end
